import {createRouter, createWebHistory, RouteRecordRaw} from 'vue-router'

export const constantRoutes: Array<RouteRecordRaw> = [

    {
        path: '/',
        redirect: '/index'
    },
    {
        name: "index",
        path: "/index",
        component: () => import('../pages/Index.vue'),
        redirect: '/menu',
        meta: {
            title: "主页",
            icon: "Operation"
        },
        children: [{
            name: "menu",
            path: "/menu",
            component: () => import('../pages/Menu.vue'),
            meta: {
                title: "菜单",
                icon: "Operation"
            },
            children: []
        },
            {
                name: "camera",
                path: "/camera",
                component: () => import('../pages/Camera.vue'),
                meta: {
                    title: "相机",
                    icon: "Operation"
                },
                children: []
            },
            {
                name: "phone",
                path: "/phone",
                component: () => import('../pages/Phone.vue'),
                meta: {
                    title: "电话",
                    icon: "Operation"
                },
                children: []
            },
        ]
    },
    {
        path: '/:catchAll',
        name: '/404',
        component: () => import('../components/404.vue'),
        children: []
    },

]


export const router = createRouter({
    history: createWebHistory(import.meta.env.BASE_URL),
    linkActiveClass: 'router-checked',
    routes: constantRoutes
})


// 白名单
//const whiteList = ['/login'] // no redirect whitelist
export const permissionsList = ['/Home', '/login', '/HomePage', '/main'] // no redirect whitelist
router.beforeEach((_to, _from, next) => {
    next()

    /*  console.log(to)
      console.log(from)
      console.log(next)
      const env = import.meta.env
      console.log(env)*/
    /*      if (getToken() != undefined && permissionsList.indexOf(to.path) !== -1) {
              next()
              //没有token并且是前往login页面
          } else if (getToken() == undefined && whiteList.indexOf(to.path) !== -1) {
              // 未登录,跳转到登陆页面
              next()
          } else {
              next({
                  path: '/login'
              })
          }*/
})
export default router
